<template>
  <div>
    <SkuDetail ref="SkuDetail" class="array" />
    <el-dialog
      class="idadd"
      title="热销详情"
      :visible.sync="dialogVisible"
      width="70%"
    >
      <!-- 条件查询 -->
      <el-card class="card" shadow="never">
        <div slot="header" class="clearfix">
          <span class="condtion">条件查询</span>
        </div>
        <!-- 条件查询内容 -->
        <div>
          <el-form
            size="mini"
            :inline="true"
            :model="searchFrom"
            class="demo-form-inline"
          >
            <el-form-item class="users">
              <el-input
                v-model="searchFrom.name"
                placeholder="商品名称/模糊查询"
              ></el-input>
            </el-form-item>
            <el-form-item class="users">
              <el-input
                v-model="searchFrom.title"
                placeholder="商品货号"
              ></el-input>
            </el-form-item>

            <el-form-item class="users">
              <el-select
                v-model="searchFrom.recommendStatus"
                placeholder="上架状态"
                size="mini"
              >
                <el-option
                  v-for="item in options"
                  :key="item.id"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item class="users">
              <el-select
                v-model="searchFrom.recommendStatus"
                placeholder="审核状态"
                size="mini"
              >
                <el-option
                  v-for="item in optionser"
                  :key="item.id"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <!-- 
            <el-form-item label="编辑类型" class="users">
              <el-input placeholder="编辑类型"></el-input>
            </el-form-item> -->
            <el-form-item class="usered">
              <el-button @click="reset">重置</el-button>
              <el-button type="primary" @click="doSearch">查询</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-card>
      <!-- 文章列表table表单 -->
      <el-card shadow="never" class="card">
        <div slot="header" class="clearfix">商品列表</div>
        <el-table :data="tableData" style="width: 100%" max-height="450" border>
          <el-table-column label="序号" fixed type="index" width="50">
          </el-table-column>

          <el-table-column width="200" align="center">
            <template slot-scope="scope">
              <el-button
                icon="el-icon-search"
                circle
                @click="searchs(scope.row)"
              ></el-button>
            </template>
          </el-table-column>
          <el-table-column label="商品图片" width="200" align="center">
            <template slot-scope="scope">
              <img
                style="width: 100px; height: 100px"
                :src="scope.row.pic"
                alt=""
              />
            </template>
          </el-table-column>
          <el-table-column
            prop="createTime"
            label="商品名称"
            width="200"
            align="center"
          >
            <template slot-scope="scope">
              <div>{{ scope.row.name }}</div>
              <div>品牌：{{ scope.row.brandName }}</div>
              <div>{{ scope.row.description }}</div>
            </template>
          </el-table-column>
          <el-table-column label="商品价格" width="200" align="center">
            <template slot-scope="scope">
              <div>原价：{{ scope.row.price }}</div>
              <div>现价：{{ scope.row.originalPrice }}</div>
            </template>
          </el-table-column>
          <el-table-column
            prop="productCategoryName"
            label="商品类别"
            width="100"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="weight"
            label="重量"
            width="100"
            align="center"
          >
          </el-table-column>
        </el-table>
      </el-card>
      <!-- 分页 -->
      <el-pagination
        :current-page="page.currentPage"
        :page-sizes="page.pageSizes"
        :page-size="page.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
      </el-pagination>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import marketing from '@/api/marketing.js'
import SkuDetail from '../componentser/SkuDetail.vue'
import mixin from '@/mixins'
export default {
  mixins: [mixin],
  components: {
    SkuDetail,
  },
  data() {
    return {
      searchFrom: {}, //输入框里的对象
      form: {}, //实际搜索要用的表单
      tableData: [], //文章列表数据
      dialogVisible: false,
      options: [
        {
          label: '上架',
          value: '0',
        },
        {
          label: '未上架',
          value: '1',
        },
      ],
      optionser: [
        {
          label: '审核',
          value: '0',
        },
        {
          label: '未审核',
          value: '1',
        },
      ],
    }
  },
  created() {},
  mounted() {
    this.productsByPageApi()
  },
  methods: {
    productsByPageApi() {
      marketing
        .productsByPageApi(this.page.currentPage, this.page.pageSize, this.from)
        .then(res => {
          console.log(res, 'res')
          if (res.success) {
            this.tableData = res.data.rows //获取到线上文字地址
            this.page.total = res.data.total //获取文章总条数
          } else {
            this.$message.error('请求失败')
          }
          console.log(this.tableData, 'this.tableData')
        })
    },

    submit() {
      this.dialogVisible = false
    },
    //子组件的打开方法
    open() {
      this.dialogVisible = true
      this.productsByPageApi()
    },
    //每页多少条 改变时触发事件
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.page.pageSize = val
      this.productsByPageApi()
    },
    //修改页触发的事件
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.page.currentPage = val
      this.productsByPageApi()
    },
    searchs(row) {
      console.log(row, 'rowrowrow')
      this.$refs.SkuDetail.open(row)
    },
    doSearch() {
      this.page = {
        currentPage: 1, //当前页
        pageSizes: [10, 20, 30, 40],
        pageSize: 10, //每页多少条数据
        total: 0, //总数据条数
      }
      this.from = Object.assign({}, this.searchFrom)
      this.productsByPageApi()
      console.log(this.searchFrom, 'this.searchFrom')
      console.log(this.from, 'this.from')
    },
    //重置
    reset() {
      this.searchFrom = {}
      this.page = {
        currentPage: 1, //当前页
        pageSizes: [10, 20, 30, 40],
        pageSize: 10, //每页多少条数据
        total: 0, //总数据条数
      }
      this.productsByPageApi()
    },
  },
}
</script>

<style scoped lang="scss">
.idadd ::v-deep .el-dialog {
  height: 1000px !important;
}
</style>